1 using UnityEngine;
2 using
System.Collections;
3
4 namespace
GamePlay
5 {
6     
public class Effect : MonoBehaviour
7     {
8
9         
public Transform mapObjectTransform;
10         
public bool isFollowing;
11         
public float stateTime;
12         
public float offsetX;
13         
public float offsetY;
14
15         
private bool isRunning;
16
17         
public void Start()
18         {
19             isRunning =
true;
20             transform.localPosition =
new Vector3(mapObjectTransform.localPosition.x + offsetX, mapObjectTransform.localPosition.y + offsetY, transform.localPosition.z);
21         }
22
23         
void Update()
24         {
25             
if (isRunning)
26             {
27                 
if (isFollowing && stateTime != -1)
28                 {
29                     transform.localPosition =
new Vector3(mapObjectTransform.localPosition.x + offsetX, mapObjectTransform.localPosition.y + offsetY, transform.localPosition.z);
30                     stateTime -= Time.deltaTime;
31                     
if (stateTime <= 0)
32                         Destroy(gameObject);
33                     
if (mapObjectTransform.gameObject.GetComponent<Animal>() != null)
34                         
if (mapObjectTransform.GetComponent<Animal>().IsRevival())
35                         {
36                             Destroy(gameObject);
37                         }
38                 }
39                 
else if (isFollowing)
40                 {
41                     transform.localPosition =
new Vector3(mapObjectTransform.localPosition.x + offsetX, mapObjectTransform.localPosition.y + offsetY, transform.localPosition.z);
42                     
if (mapObjectTransform.gameObject.GetComponent<Animal>() != null)
43                         
if (mapObjectTransform.GetComponent<Animal>().IsRevival())
44                         {
45                             Destroy(gameObject);
46                         }
47                 }
48             }
49         }
50
51         
public void setRunning(bool isRunning)
52         {
53             
this.isRunning = isRunning;
54             
if (gameObject.GetComponent<Bapk.Animation>() != null)
55                 gameObject.GetComponent<Bapk.Animation>().setRunning(isRunning);
56
57         }
58     }
59 }



Trò chơi đua xe động vật trong UNITY Engine 114.855 lượt xem

Gõ tìm kiếm nhanh...